package com.tencent.sr.iris.basic.saas.restapi.group;

import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskSecondRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskThirdRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.BaseRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.GroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.GroupTaskSecondRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.RankConfigRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.TaskStatisticsRequest;
import com.tencent.sr.iris.activity.interfaces.response.group.*;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.OperateSecondBoardResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.task.TaskCommissionResponse;
import com.tencent.sr.iris.basic.saas.common.enums.YesOrNoEnum;
import com.tencent.sr.iris.basic.saas.dependency.group.GroupTaskBoardDependency;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "团长任务看板", value = "团长任务看板")
@RestController
@RequestMapping(value = {"/iris/activity/saas/v1/grouptask/board"})
public class GroupTaskBoardController {
    @Resource
    private GroupTaskBoardDependency groupTaskBoardDependency;
    @Resource
    private AppUser appUser;


    @PostMapping("/queryGroupTaskBoard")
    @ApiOperation(value = "查询团长任务一级列表-团长视角")
    HttpResult<PaginationResponse<GroupTaskBoardResponse>> queryGroupTaskBoard(
            @RequestBody @Validated PaginationRequest<GroupTaskRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        request.getQueryCriteria().setIrisUid(Arrays.asList(appUser.getUid()));
        return groupTaskBoardDependency.queryGroupTaskBoard(request);
    }

    @PostMapping("/queryGroupTaskSecondBoard/specialSprint")
    @ApiOperation(value = "查询团长任务二级列表-团长视角(特邀会员冲刺赛)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryGroupTaskSecondBoardSpecialSprint(
            @RequestBody @Validated PaginationRequest<GroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.queryGroupTaskSecondBoardSpecialSprint(request);
    }

    @PostMapping("/queryGroupTaskSecondBoard/invite")
    @ApiOperation(value = "查询团长任务二级列表-团长视角(邀新有礼)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryGroupTaskSecondBoardInvite(
            @RequestBody @Validated PaginationRequest<GroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.queryGroupTaskSecondBoardInvite(request);
    }
    
    @PostMapping("/queryGroupTaskSecondBoard/firstOrder")
    @ApiOperation(value = "查询团长任务二级列表-团长视角(首单任务)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryGroupTaskSecondBoardFirstOrder(
            @RequestBody @Validated PaginationRequest<GroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.queryGroupTaskSecondBoardFirstOrder(request);
    }

    @PostMapping("/queryGroupTaskSecondBoard/sprint")
    @ApiOperation(value = "查询团长任务二级列表-团长视角(GMV冲刺赛/销量冲刺赛)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryGroupTaskSecondBoardSprint(
            @RequestBody @Validated PaginationRequest<GroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.queryGroupTaskSecondBoardSprint(request);
    }

    @PostMapping("/queryGroupTaskSecondBoardNormal")
    @ApiOperation(value = "查询团长任务二级列表-团长视角(团推团)")
    HttpResult<PaginationResponse<GroupNormalTaskSecondResponse>> queryGroupTaskSecondBoardNormal(
            @RequestBody @Validated PaginationRequest<GroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.queryGroupTaskSecondBoardNormal(request);
    }

    @PostMapping("/queryGroupTaskSecondBoard/rank")
    @ApiOperation(value = "查询团长任务二级列表-团长视角(排行榜)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryGroupTaskSecondBoardRank(
            @RequestBody @Validated PaginationRequest<GroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new GroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.queryGroupTaskSecondBoardRank(request);
    }

    @PostMapping("/queryAdvisorBoard")
    @ApiOperation(value = "查询团长任务一级列表-导师视角")
    HttpResult<PaginationResponse<AdvisorBoardResponse>> queryAdvisorBoard(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskRequest> request) {
        AdvisorGroupTaskRequest queryCriteria = request.getQueryCriteria();

        if (Objects.isNull(queryCriteria)) {
            queryCriteria = new AdvisorGroupTaskRequest();
            request.setQueryCriteria(queryCriteria);
        }
        queryCriteria.setUid(appUser.getUid());
        queryCriteria.setSaasId(appUser.getSaasId());
        if (Objects.equals(queryCriteria.getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            queryCriteria.setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorBoard(request);
    }


    @PostMapping("/queryAdvisorSecondBoardInvite")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(邀新有礼)")
    HttpResult<PaginationResponse<AdvisorBoardInviteSecondResponse>> queryAdvisorSecondBoardInvite(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondBoardInvite(request);
    }

    @PostMapping("/queryAdvisorSecondBoardFirstOrder")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(首单任务)")
    HttpResult<PaginationResponse<AdvisorBoardFirstOrderSecondResponse>> queryAdvisorSecondBoardFirstOrder(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondBoardFirstOrder(request);
    }

    @PostMapping("/queryAdvisorSecondBoardSprint")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(GMV冲刺赛/销量冲刺赛)")
    HttpResult<GroupTaskPaginationResponse<AdvisorBoardSprintSecondResponse>> queryAdvisorSecondBoardSprint(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondBoardSprint(request);
    }

    @PostMapping("/queryAdvisorSecondBoardCommission")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(佣金回滚)")
    HttpResult<PaginationResponse<AdvisorBoardCommissionSecondResponse>> queryAdvisorSecondBoardCommission(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondBoardCommission(request);
    }

    @PostMapping("/queryAdvisorSecondBoardNormal")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(团推团)")
    HttpResult<PaginationResponse<AdvisorNormalTaskSecondResponse>> queryAdvisorSecondBoardNormal(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondBoardNormal(request);
    }

    @PostMapping("/queryAdvisorSecondSpecialSprint")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(特邀会员冲刺赛)")
    HttpResult<GroupTaskPaginationResponse<OperateSecondBoardResponse>> queryAdvisorSecondSpecialSprint(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondSpecialSprint(request);
    }

    @PostMapping("/queryAdvisorThirdBoardInvite")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(邀新有礼)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryAdvisorThirdBoardInvite(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdBoardInvite(request);
    }
    
    @PostMapping("/queryAdvisorThirdBoardFirstOrder")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(首单任务)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryAdvisorThirdBoardFirstOrder(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdBoardFirstOrder(request);
    }

    @PostMapping("/queryAdvisorThirdBoardSprint")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(GMV冲刺赛/销量冲刺赛)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryAdvisorThirdBoardSprint(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdBoardSprint(request);
    }

    @PostMapping("/queryAdvisorThirdBoardCommission")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(佣金回滚)")
    HttpResult<PaginationResponse<AdvisorBoardCommissionThirdResponse>> queryAdvisorThirdBoardCommission(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdBoardCommission(request);
    }


    @PostMapping("/queryAdvisorThirdBoardNormal")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(团推团)")
    HttpResult<PaginationResponse<GroupNormalTaskSecondResponse>> queryAdvisorThirdBoardNormal(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdBoardNormal(request);
    }

    @PostMapping("/queryAdvisorThirdSpecialSprint")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(特邀会员冲刺赛)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryAdvisorThirdSpecialSprint(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdSpecialSprint(request);
    }

    @PostMapping("/queryAdvisorTaskStatistics")
    @ApiOperation(value = "导师视角-团长任务统计")
    HttpResult<TaskStatisticsResponse> queryAdvisorTaskStatistics(@RequestBody @Validated TaskStatisticsRequest req) {
        if (Objects.isNull(req)) {
            req = new TaskStatisticsRequest();
        }
        req.setSaasId(appUser.getSaasId());
        req.setUid(appUser.getUid());
        req.setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorTaskStatistics(req);
    }

    @PostMapping("/queryOperateTaskStatistics")
    @ApiOperation(value = "营销视角-团长任务统计")
    HttpResult<TaskStatisticsResponse> queryOperateTaskStatistics(@RequestBody @Validated TaskStatisticsRequest req) {
        if (Objects.isNull(req)) {
            req = new TaskStatisticsRequest();
        }
        req.setSaasId(appUser.getSaasId());
        req.setUid(appUser.getUid());
        return groupTaskBoardDependency.queryOperateTaskStatistics(req);
    }


    @PostMapping("/queryUserIdentity")
    @ApiOperation(value = "用户用户身份校验")
    HttpResult<Integer> queryUserIdentity() {
       return groupTaskBoardDependency.queryUserIdentity(appUser.getUid());
    }

    @PostMapping("/queryAdvisorSecondBoardRank")
    @ApiOperation(value = "查询团长任务二级列表-导师视角(排行榜)")
    HttpResult<PaginationResponse<AdvisorBoardRankSecondResponse>> queryAdvisorSecondBoardRank(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskSecondRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        if (Objects.equals(request.getQueryCriteria().getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            request.getQueryCriteria().setAdviserId(appUser.getUid());
        }
        return groupTaskBoardDependency.queryAdvisorSecondBoardRank(request);
    }

    @PostMapping("/queryAdvisorThirdBoardRank")
    @ApiOperation(value = "查询团长任务三级列表-导师视角(排行榜)")
    HttpResult<PaginationResponse<GroupTaskBoardSecondResponse>> queryAdvisorThirdBoardRank(
            @RequestBody @Validated PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        if (Objects.isNull(request.getQueryCriteria())) {
            request.setQueryCriteria(new AdvisorGroupTaskThirdRequest());
        }
        request.getQueryCriteria().setUid(appUser.getUid());
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        //request.getQueryCriteria().setAdviserId(appUser.getUid());
        return groupTaskBoardDependency.queryAdvisorThirdBoardRank(request);
    }

    @PostMapping({"/queryRankConfigs"})
    @ApiOperation("排行榜任务-奖励阶段下拉列表")
    HttpResult<List<RankAwardConfigResponse>> queryRankConfigs(@RequestBody @Validated RankConfigRequest request) {
        return groupTaskBoardDependency.queryRankConfigs(request);
    }

    @PostMapping({"/taskReward"})
    @ApiOperation("任务收益数据")
    HttpResult<TaskCommissionResponse> taskReward(@RequestBody @Validated BaseRequest request) {
        if (Objects.isNull(request)) {
            request = new BaseRequest();
        }
        request.setSaasId(appUser.getSaasId());
        return groupTaskBoardDependency.taskReward(request);
    }

}
